package com.mo.axion.support.utils;

import com.dtp.core.DtpRegistry;
import com.dtp.core.thread.DtpExecutor;
import com.mo.axion.support.config.ThreadPoolExecutorShutdownDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Mo
 * @createTime 2024/2/18 15:23
 * @description 线程池工具类
 */
@Component
public class ThreadPoolUtils {
    private static final String SOURCE_NAME = "axion";
    @Autowired
    private ThreadPoolExecutorShutdownDefinition shutdownDefinition;

    /**
     * 将当前线程池加入到动态线程池内
     * 注册线程池交给spring管理，实现延迟关闭
     * @param dtpExecutor
     */
    public void register(DtpExecutor dtpExecutor) {
        DtpRegistry.register(dtpExecutor, SOURCE_NAME);
        shutdownDefinition.registryExecutor(dtpExecutor);
    }
}
